#region Copyright 2006 - Evolution Tecnologia Ltda.
//
// Author: Rafael Franco Carvalho (rafael@Evolutiontec.com.br)
//
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, eletronic, mechanical or otherwise, is prohibited
// without the prior written permission of the author.
//
// Filename: Logs.cs
#endregion


using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace csharp.rad.general
{
    public class Logs
    {
        String fileName;

        public Logs(String fileName)
        {
            this.fileName = fileName;
            //Check if file extension has been informed
            if ((Path.GetExtension(this.fileName) == null) || (Path.GetExtension(this.fileName) == ""))
            {
                this.fileName = this.fileName + ".log";
            }
            //Check if file path has been informed
            if ((Path.GetDirectoryName(this.fileName) == null) || (Path.GetDirectoryName(this.fileName) == ""))
            {
                String filePath;
                filePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath.ToString());
                this.fileName = filePath + "\\" + this.fileName;
            }
        }

        public void Write(String message)
        {
            StreamWriter myStreamWriter;
            if (File.Exists(fileName))
            {
                myStreamWriter = File.AppendText(fileName);
            }
            else
            {
                myStreamWriter = File.CreateText(fileName);
            }
            myStreamWriter.WriteLine(System.DateTime.Now.ToString("[dd/MM/yyyy HH:mm:ss]: ") + message);
            myStreamWriter.Close();
        }
    }
}
